﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace BaseData.HelperEzui
{
    public class GetTreeResx
    {
        public List<EzuiTreeViews<string>> Get(string id)
        {
            var traversalHelp = new TreeMethod().Fix<string, List<EzuiTreeViews<string>>, int>(f => (current, pathList, index) =>
            {
                foreach (var path in Directory.GetDirectories(current)) // 访问当前目录的文件夹
                {
                    var filesCount = new FileInfo(path);
                    var folderlist = new EzuiTreeViews<string>
                    {
                        id = path,
                        text = path.Substring(path.LastIndexOf('\\') + 1, path.Length - path.LastIndexOf('\\') - 1) + "[" + Directory.GetFiles(path).Count(w => w.EndsWith(".ascx")) + "]",
                        state = (!Directory.GetDirectories(path).Any() ? Enums.TreeStat.Open : Enums.TreeStat.Closed).ToString().ToLower(),
                    };
                    pathList.Add(folderlist); // 添加当前目录到pathList
                    // f(path, pathList, index++); // 递归调用
                }
            });
            var result = new List<EzuiTreeViews<string>>();
            traversalHelp(id, result, 0);
            return result;
        }
    }
}
